/*
 * $Id: PrcToTaskCategoryDAO.java,v 1.4 2009/07/10 15:18:36 navdeep_mahajan Exp $
 * 
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.common.database.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.HibernateException;

import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.common.database.pojo.CfgPrcToTaskCategory;

/**
 * @author 212042764
 * 
 */
public class PrcToTaskCategoryDAO extends BaseDAO implements
		IPrcToTaskCategoryDAO {
	/**
	 * Eclispe generated
	 */
	private static final long serialVersionUID = 7738629131201438582L;
	private static final String TABLE_NAME = "com.ge.healthcare.autosc.common.database.pojo.CfgPrcToTaskCategory";
	private static final String COL_SERVER_NAME = "serverName";
	private static final String COL_CATEGORY_NAME = "cfgTaskCategoryInfo.taskCategory";
	/**
	 * @param tableName
	 */
	public PrcToTaskCategoryDAO() {
		super(TABLE_NAME);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.ge.healthcare.autosc.common.database.dao.IPrcToTaskCategoryDAO#
	 * getCategoriesForPrcServer(java.lang.String)
	 */
	public List<CfgPrcToTaskCategory> getPrcToTaskCategoryDetailsForServer(
			String prcServerName) {
		List<?> rtvdMapping = findByProperty(COL_SERVER_NAME, prcServerName);
		if (ASCUtil.isNullOrEmptyList(rtvdMapping)) {
			return null;
		}
		List<CfgPrcToTaskCategory> allowedTaskCategoryLst = new ArrayList<CfgPrcToTaskCategory>();
		for (int iCount = 0; iCount < rtvdMapping.size(); iCount++) {
			allowedTaskCategoryLst.add((CfgPrcToTaskCategory)rtvdMapping.get(iCount));
		}
		return allowedTaskCategoryLst;
	}

	/* (non-Javadoc)
	 * @see com.ge.healthcare.autosc.common.database.dao.IPrcToTaskCategoryDAO#getPrcTaskCategoryInfoForPrcServer(java.lang.String, java.lang.String)
	 */
	public CfgPrcToTaskCategory getPrcTaskCategoryInfoForPrcServer(
			String prcServerName, String categoryName) {
		Map<String, Object> whereClause = new HashMap<String, Object>();
		whereClause.put(COL_SERVER_NAME, prcServerName);
		whereClause.put(COL_CATEGORY_NAME, categoryName);
		List<?> rtvdCategories = findByProperties(whereClause);
		if (ASCUtil.isNullOrEmptyList(rtvdCategories)) {
			return null;
		}
		if (rtvdCategories.size() > 1) {
			throw new HibernateException(
					new StringBuffer()
							.append("getTaskCategoryInfoForPrcServer returned:")
							.append(rtvdCategories.size())
							.append(
									" while it was expected to return single row, for servername:")
							.append(prcServerName).append(
									" and categoryName as:").append(
									categoryName).append(" \nResults:").append(
									rtvdCategories).toString());
		}
		return ((CfgPrcToTaskCategory) rtvdCategories.get(0));
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#save(java.lang.Object)
	 */
	public void save(Object pojo) {
		super.save(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.IRequestTypeDAO#saveAlways(java.lang.Object)
	 */
	public void saveAlways(Object pojo) {
		super.save(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#deleteByID(java.lang.Object)
	 */
	public void deleteByID(Object pojo) {
		super.deleteByID(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#refresh(java.lang.Object)
	 */
	public void refresh(Object pojo) {
		super.refresh(pojo);
	}
}
